package com.sunagy.demand.backend.service.impl;

import com.sunagy.demand.backend.entity.CustomerProgressPaper;
import com.sunagy.demand.backend.VO.response.CustomerProgressPaperResponseVO;
import com.sunagy.demand.backend.repository.CustomerProgressPaperRepository;
import com.sunagy.demand.backend.service.CustomerProgressPaperService;
import com.sunagy.demand.backend.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * desc：#TODO fill me ！
 * author：三餘無夢生
 * date：2018/5/15
 * time：下午1:46
 */
@Service
public class CustomerProgressPaperServiceImpl implements CustomerProgressPaperService {

    @Autowired
    private CustomerProgressPaperRepository customerProgressPaperRepository;

    @Override
    public List<CustomerProgressPaperResponseVO> getListByCustomerProgressId(Integer customerProgressId) {
        List<CustomerProgressPaper> customerProgressPaperList = customerProgressPaperRepository.findByCustomerProgressId(customerProgressId);
        List<CustomerProgressPaperResponseVO> customerProgressPaperResponseVOList = (List<CustomerProgressPaperResponseVO>)BeanUtil.copyPropertiesList(customerProgressPaperList,CustomerProgressPaperResponseVO.class);
        return customerProgressPaperResponseVOList;
    }

    @Override
    @Transactional
    public CustomerProgressPaperResponseVO add(CustomerProgressPaper customerProgressPaper) {
        customerProgressPaper = customerProgressPaperRepository.save(customerProgressPaper);
        CustomerProgressPaperResponseVO customerProgressPaperResponseVO = new CustomerProgressPaperResponseVO();
        BeanUtil.copyProperties(customerProgressPaperResponseVO,customerProgressPaper);
        return customerProgressPaperResponseVO;
    }
}
